﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MaximumNestingDepthoftheParentheses
{
    public class Solution
    {
        public int MaxDepth(string s)
        {
            var stack = new Stack<char>();
            var maxDepth = 0;
            foreach (var c in s)
            {
                if (c == '(')
                {
                    stack.Push(c);
                }
                else if (c == ')')
                {
                    if (maxDepth < stack.Count)
                    {
                        maxDepth = stack.Count;
                    }
                    stack.Pop();
                }
            }
            return maxDepth;
        }
    }
}
